package uk.org.landeg.euler.problems;

import java.util.HashMap;
import java.util.Map;

import uk.org.landeg.euler.problems.framework.AbstractProblem;
import uk.org.landeg.euler.problems.framework.ProblemLauncher;
import uk.org.landeg.euler.problems.lib.NumbersLib;

public class Problem005 extends AbstractProblem {
	public static void main(String[] args) {
		ProblemLauncher launcher= new ProblemLauncher(new Problem005());
		launcher.solve();
	}
	
	@Override
	public String getDescription() {
		return "What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?";
	}

	@Override
	public Integer getProblemNumber() {
		// TODO Auto-generated method stub
		return 5;
	}

	@Override
	public Object solve() {
		notes.add("get prime factors for numbers 1..20");
		Map<Long,Integer> theseFactors,factors = new HashMap<Long,Integer>();
		for (int n = 2 ; n <= 20 ; n++) {
			theseFactors = NumbersLib.primeFactors(n);
			notes.add(n + "\t" + theseFactors);
			for (long pf : theseFactors.keySet()) {
				if (factors.get(pf) == null || factors.get(pf) < theseFactors.get(pf)) {
					factors.put(pf, theseFactors.get(pf));
				}
			}
		}
		notes.add("Higest order prime factors for all numbers : " + factors);
		long answer = 1L;
		for (long pf : factors.keySet()) {
			answer *= Math.pow(pf, factors.get(pf));
		}
		return answer;
	}
}
